import numpy as np
import matplotlib.pyplot as plt

# 设置中文显示
plt.rcParams["font.family"] = ["WenQuanYi Micro Hei"]
plt.rcParams["axes.unicode_minus"] = False  # 正确显示负号

# 五次多项式系数 a*x⁵ + b*x⁴ + c*x³ + d*x² + e*x + f
# coefficients = [-0.0615133, -0.00734267, 0, 0.012365, -0.00452213, 0.000446476]
# coefficients = [-0.0647312, 0.00151422, 0, 0.00622092, -0.00204412, 0.000178426]
# -0.0580237, 0.000586059, 0, 0.00579499, -0.00189569, 0.000165105
# -0.650691, -0.486031, 0, -0.106693, 0.047604, -0.00514012
# -0.110438, 0.0086924, 0, 0.0139963, -0.00538445, 0.000545236
coefficients = [-0.146475, 0.0308952, 0, 0.0113009, -0.00472059, 0.000496196]
a, b, c, d, e, f = coefficients

# 生成x值范围，这里选择-2到2之间，可以根据需要调整
x = np.linspace(0, 4, 20)

# 计算五次多项式的y值
y = f * x**5 + e * x**4 + d * x**3 + c * x**2 + b * x + a

# 创建图形
plt.figure(figsize=(10, 6))

# 绘制曲线
plt.plot(x, y, 'b-', linewidth=2, label=f'五次多项式: y = {a:.6f}x^5 + {b:.6f}x⁴ + {c:.6f}x³ + {d:.6f}x² + {e:.6f}x + {f:.6f}')

# 添加参考线
plt.axhline(y=0, color='k', linestyle='--', alpha=0.3)
plt.axvline(x=0, color='k', linestyle='--', alpha=0.3)

# 设置标题和坐标轴标签
plt.title('五次多项式曲线', fontsize=14)
plt.xlabel('x', fontsize=12)
plt.ylabel('y', fontsize=12)

# 添加网格和图例
plt.grid(True, alpha=0.3)
plt.legend()

# 调整布局并显示
plt.tight_layout()
plt.show()
    